<template>
  <div>
    <div v-if="state === 0" class="wrap bgw">
      <div class="nav">
        <div>
          <p>100</p>
          <p>余额</p>
          <p class="point" @click="changeState(2)">提现</p>
        </div>
        <div>
          <p>100</p>
          <p>银行卡</p>
          <p class="point" @click="changeState(5)">查看</p>
        </div>
      </div>
      <div class="title">
        余额变动记录
        <i></i>
      </div>
      <div class="list">
        <div class="top">
          <p class="one">日期</p>
          <p class="one">余额变化</p>
          <p class="one">详细说明</p>
        </div>
        <div v-for="(item, i) in record" :key="i">
          <p class="one"> {{ item.addTime }} </p>
          <p class="one"> {{ item.money }} </p>
          <p class="one fll"> {{ item.note }} </p>
        </div>
      </div>
    </div>
    <cash v-if="state === 2" :userList="userList" @changeState="changeState"></cash>
    <card v-if="state === 5" @changeState="changeState"></card>
  </div>
</template>
<script>
import cash from "./cash"; // 提现
import card from "./card"; // 银行卡

// 获取财务日志
import { getFinancelist } from "@/request/personnel";
import { usergetinfo } from "@/request/user";
import moment from "moment"
export default {
  components: { cash, card },
  data() {
    return {
      state: 0,
      record: "",
      userList: []
    };
  },
  created() {
    getFinancelist({
      token: this.$token,
      // type: 1
    }).then(res => {
      this.record = res.data.data;
      this.record.sort((a,b) => b.add_time - a.add_time);
      this.record.forEach(item => {
        item.addTime = moment(item.add_time).format('YYYY-MM-DD HH:mm');
      })
      // 取前10条数据渲染
      this.record.splice(0, 10);
    });
    this.start();
  },
  methods: {
    start() {
      usergetinfo({token: this.$token})
        .then(res => {
          this.userList = res.data;
        })
    },
    changeState(num) {
      this.state = num;
    }
  }
};
</script>
<style lang="less" scoped>
.list {
  min-height: 400px;
  padding-bottom: 60px;
  > div {
    height: 69px;
    line-height: 69px;
    font-size: 16px;
    color: #4d4d4d;
    display: flex;
  }
  .top {
    padding-top: 20px;
  }
  .top p {
    height: 28px;
    line-height: 28px;
    border-left: 1px solid #dbdbdb;
  }
  > div:nth-child(odd) {
    background: #f8f8f8;
  }

  p {
    width: 40%;
    text-align: center;
  }
  .fll {
    text-indent: 62px;
    text-align: left;
  }
}
.title {
  height: 68px;
  line-height: 68px;
  color: #4eeec8;
  border-bottom: 1px solid #e6e6e6;
  position: relative;
  padding-left: 50px;
  i {
    position: absolute;
    bottom: 0;
    left: 30px;
    height: 1px;
    width: 146px;
    border-bottom: 2px solid #4eeec8;
  }
}
.nav {
  display: flex;
  border-bottom: 1px solid #e6e6e6;
  > div {
    text-align: center;
    width: 50%;
    height: 240px;
    padding-top: 60px;
  }
  p {
    margin: auto;
    margin-bottom: 14px;
  }
  > div > p:nth-of-type(1) {
    font-size: 36px;
  }
  > div > p:nth-of-type(2) {
    font-size: 18px;
  }
  > div > p:nth-of-type(3) {
    font-size: 18px;
    color: #4eeec8;
  }
}
// 增加
.point {
  cursor: pointer;
}
</style>